function validateRegForm() {
	var valid = true;
	if (!validateNotEmpty($("#username"))) {
		valid = false;
	}
	if (!validateNotEmpty($("#firstname"))) {
		valid = false;
	}
	if (!validateNotEmpty($("#address"))) {
		valid = false;
	}
	if (!validateNotEmpty($("#lastname"))) {
		valid = false;
	}
	if (!validatePassword($("#password"))) {
		valid = false;
	}
	return valid;
}

/*
 * Start of common validation methods
 */

/**
 * Validates password strength
 * 
 * @returns true, if the password is good enough
 */
function validatePassword(element) {
	if (element.val().length < 5) {
		setValidationMsg(element,'error','Nem elég hosszú (legalább 5 karakter)');
		return false;
	}
	var desc = new Array();
	desc[0] = {
		text : 'Gyenge',
		css : 'warning'
	};
	desc[1] = {
		text : 'Elmegy...',
		css : 'warning'
	};
	desc[2] = {
		text : 'Közepes',
		css : 'info'
	};
	desc[3] = {
		text : 'Egész jó',
		css : 'info'
	};
	desc[4] = {
		text : 'Erős',
		css : 'success'
	};
	desc[5] = {
		text : 'Nagyon erős',
		css : 'success'
	};
	var score = 0;
	// if password bigger than 8 give 1 point
	if (element.val().length > 8)
		score++;
	// if password has both lower and uppercase characters give 1 point
	if ((element.val().match(/[a-z]/)) && (element.val().match(/[A-Z]/)))
		score++;
	// if password has at least one number give 1 point
	if (element.val().match(/\d+/))
		score++;
	// if password has at least one special caracther give 1 point
	if (element.val().match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/))
		score++;
	// if password bigger than 12 give another 1 point
	if (element.val().length > 12)
		score++;

	setValidationMsg(element,desc[score].css,desc[score].text);
	return true;
}

/**
 * If the given element is empty, adds error message to UI
 * 
 * @param element:
 *            jquery element
 * @returns true, if element is not empty
 */
function validateNotEmpty(element) {
	var value = element.val();
	if (value == "") {
		setValidationMsg(element,'error','Kötelező megadni');
		return false;
	} else {
		setValidationMsg(element,'','');
		return true;
	}
}

function setValidationMsg(element, cssClass, msg){
	element.closest('.control-group').attr('class', 'control-group');
	if (cssClass!=null && cssClass!='') {
		element.closest('.control-group').addClass(cssClass);
	} 
	element.next('.help-inline').html(msg);
}

/*
 * End of common validation methods
 */